﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WebAPI.Filters;
using wt.wine.Application.Common.Models;
using wt.wine.Application.ManageUserTable;
using wt.wine.Application.ManageUserTable.Command;
using wt.wine.Application.ManageUserTable.Queries;

namespace WebAPI.Controllers.V1
{
    [ApiController]
    [Route("[controller]/[action]")]
    [LoginFilter]
    public class ManageUserTableController : ApiControllerBase
    {
        /// <summary>
        /// 【平台|经销商】添加员工
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [PermissioneFilter("AddUserTable,ptAddUserTable")]
        [HttpPost]
        public async Task<Json<string>> AddUserTable([FromBody] AddUserTableCommand command)
        {
            return await Mediator.Send(command);
        }

        /// <summary>
        /// 【平台|经销商】修改员工
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [PermissioneFilter("AddUserTable,ptAddUserTable")]
        [HttpPost]
        public async Task<Json<string>> EditUserTable([FromBody] EditUserTableCommand command)
        {
            return await Mediator.Send(command);
        }

        /// <summary>
        /// 【平台|经销商】修改员工
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [PermissioneFilter("AddUserTable,ptAddUserTable,GetUserList,ptGetUserList")]
        public async Task<Json<GetUserTableByIdDTO>> GetUserTableById([FromBody] GetUserTableByIdQueries query)
        {
            return await Mediator.Send(query);
        }

        /// <summary>
        /// 【平台|经销商】获取员工列表 --确认两端都用的
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [PermissioneFilter("GetUserList,ptGetUserList")]
        [HttpPost]
        public async Task<Json<PaginatedList<GetUserTableByIdDTO>>> GetUserList([FromBody] GetUserListQueries query)
        {
            return await Mediator.Send(query);
        }
    }
}
